package com.example.administrator.yuejian2.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.adapter.TrainAdapter;
import com.example.administrator.yuejian2.bean.TrainBean;
import com.example.administrator.yuejian2.model.TrainModel;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class TrainFragment extends Fragment {

    private RecyclerView recyclerView;
    private TrainAdapter adapter;
    private RecyclerView.LayoutManager layoutManager;
    private RetrofitListener<List<TrainBean>> listener;

    public TrainFragment() {
        // Required empty public constructor
    }


    private void initView(View v) {
        recyclerView = v.findViewById(R.id.train_recyclerview);
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        adapter = new TrainAdapter(getActivity());
        recyclerView.setAdapter(adapter);
    }
    private void club() {
        TrainModel trainModel = new TrainModel();
        trainModel.getTrainList(listener);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        listener=new RetrofitListener<List<TrainBean>>() {
            @Override
            public void onSuccess(List<TrainBean> trainBeans, int flag) {
                adapter.getTrainList(trainBeans);
            }

            @Override
            public void onFail() {

            }
        };
        View v= inflater.inflate(R.layout.fragment_train, container, false);
        initView(v);
        club();
        return v;
    }

}
